import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import CopyPlugin from 'vite-plugin-files-copy'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    CopyPlugin({
      patterns: [
        {
          from: './public/ribbon.xml', // string 相对项目下相对路径
          to: './dist/ribbon.xml', // string 相对项目下相对路径
        },
      ],
    }),
  ],
  server: {
    port: 3889,
    hmr: {
      host: '127.0.0.1',
      port: 3889,
    },
    proxy: {
      '/api': {
        target: '',
        changeOrigin: true,
        rewrite: (path: string) => path.replace(/^\/api/, ''),
      },
    },
  },
})
